package com.lire.shop.converter;

import com.lire.shop.data.Constants;
import com.lire.shop.entity.Checklist;
import com.lire.shop.entity.Order;
import com.lire.shop.entity.Product;
import com.lire.shop.model.vo.ChecklistVO;
import org.mapstruct.InheritConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

@Mapper(componentModel = "spring")
public abstract class ChecklistConverter {

//    @Mapping(source = "creatTime",target = "creatTime",dateFormat = "yyyy-MM-dd HH:mm:ss",)
//    ChecklistVO do2vo(Checklist checklist, Order order);

    public static final ChecklistConverter INSTANCE = Mappers.getMapper(ChecklistConverter.class);

    @InheritConfiguration
    public ChecklistVO do2vo(Checklist checklist, Order order, Product product) {

        ChecklistVO checklistVO = new ChecklistVO();
        LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(checklist.getCreateTime())
                , ZoneId.systemDefault());
        String format = localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        checklistVO.setCreatTime(format);

        Integer shiftMode = checklist.getShiftMode();
        String mode = "";
        if (shiftMode.equals(Constants.WALLET_OUTLAY)) {
            mode = "支出";
        } else if (shiftMode.equals(Constants.WALLET_INCOME)) {
            mode = "收入";
        }
        checklistVO.setShiftMode(mode);

        checklistVO.setBalances(checklist.getCurrentBalances());

        checklistVO.setWeight(product.getPrice());

        checklistVO.setCid(checklist.getCid());
        return checklistVO;
    }


}
